﻿/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject
{
	public struct KeyedProjectItem : IEquatable<KeyedProjectItem>
	{
		#region Public Properties
		public string Name
		{
			get
			{
				return name;
			}
		}

		public string Key
		{
			get
			{
				return key;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string name, key;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="KeyedProjectItem" /> structure.
		/// </summary>
		public KeyedProjectItem(string name, string key)
		{
			this.name = name;
			this.key = key;
		}
		#endregion

		#region Methods
		public override bool Equals(object obj)
		{
			return obj is KeyedProjectItem && Equals((KeyedProjectItem) obj);
		}

		public bool Equals(KeyedProjectItem other)
		{
			return (other.key ?? "") == (key ?? "");
		}

		public override int GetHashCode()
		{
			return (key ?? "").GetHashCode();
		}

		public override string ToString()
		{
			return name;
		}
		#endregion

		#region Operator Overloads
		public static bool operator ==(KeyedProjectItem item1, KeyedProjectItem item2)
		{
			return item1.Equals(item2);
		}

		public static bool operator !=(KeyedProjectItem item1, KeyedProjectItem item2)
		{
			return !item1.Equals(item2);
		}
		#endregion
	}
}
